<?php

namespace App\Http\Service;

use App\Http\Repository\UserRepository;
use App\Http\Criteria\MobileCriteria;

class UserService extends BaseService
{
    protected $rep;

    public function __construct(UserRepository $repository)
    {
        $this->rep = $repository;

    }

    public function register($mobile)
    {
        $nickname = substr_replace($mobile, '*****', 3, 5);

        $avatar = 'avatar.png';

        $user = $this->rep->create(['mobile' => $mobile, 'nickname' => $nickname, 'avatar' => $avatar])->fresh();

        return $user;
    }

    public function isRegister($mobile) {
        $user = $this->rep->getByCriteria(new MobileCriteria($mobile))->first();
        return $user != null ? true : false;
    }
}
